from app.company.model import Company
from app.coin.model import CoinRecord
from common.constant import CoinUseAction


def add_coins_by_use_coupon(company_id, user_id, num_of_coins, notes):
    # 充值
    company = Company.query.filter_by(id=company_id).first()
    company.current_coins = company.current_coins + num_of_coins
    # 记录
    CoinRecord.create(
        action_name=CoinUseAction.USE_COUPON['name'],
        coins_used=-num_of_coins,
        company_current_coins=company.current_coins,
        notes=notes
    )



